﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;

namespace Ken_WPF_UI.View
{
    /// <summary>
    /// WrapPanelWindow.xaml 的交互逻辑
    /// </summary>
    public partial class WrapPanelWindow : Window
    {
        public WrapPanelWindow()
        {
            InitializeComponent();
        }

        private void Window_Loaded(object sender, RoutedEventArgs e)
        {
            CreatTableInfo();
        }

        private void CreatTableInfo()
        {
            Button btn;
            StackPanel stackPanel;
            Label label1;
            Label label2;
            Random random;
            int ranCount;
            for (int i = 0; i < 50; i++)
            {

                random = new Random();
                ranCount = random.Next(0, 51);
                btn = new Button() { Name = $"btn{i}", Width = 80, Height = 80 };
                btn.Background = new SolidColorBrush(i < ranCount * 0.5 ? Colors.Red : Colors.Teal);
                btn.Margin = new Thickness(10, 8, 8, 0);


                stackPanel = new StackPanel();
                label1 = new Label() { Name = $"labelA{i}", Content = $"第{i + 1}桌", Foreground = new SolidColorBrush(Colors.White), FontWeight = FontWeights.Bold, FontFamily = new FontFamily("宋体") };
                stackPanel.Children.Add(label1);


                if (i < ranCount * 0.5)
                {
                    label2 = new Label()
                    {
                        Name = $"labelB{i}",
                        Content = $"有人入座",
                        //Foreground = new SolidColorBrush(Color.FromRgb(240, 107, 107)),
                        Foreground = new SolidColorBrush(Colors.DeepSkyBlue),
                        FontWeight = FontWeights.Bold,
                        FontFamily = new FontFamily("宋体")
                    };
                    stackPanel.Children.Add(label2);
                }

                btn.Content = stackPanel;
                this.wrapPanel1.Children.Add(btn);


            }
        }

        private void Button_Click(object sender, RoutedEventArgs e)
        {
            this.wrapPanel1.Children.Clear();
            CreatTableInfo();
        }

        private void Button_MouseMove(object sender, MouseEventArgs e)
        {
            (sender as Button).Background = new SolidColorBrush(Colors.Teal);
        }

        private void Button_MouseLeave(object sender, MouseEventArgs e)
        {
            (sender as Button).Background = new SolidColorBrush(Colors.Teal);
        }

        private void Button_MouseDown(object sender, MouseButtonEventArgs e)
        {
            (sender as Button).Background = new SolidColorBrush(Colors.GreenYellow);
        }
    }
}
